package com.dbkj.axb_conf;

import com.dbkj.common.model.AxbConf;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: Max
 * @Date: 2019/10/30 14:51
 */

public class AxbConfService {

    private static final AxbConf dao = new AxbConf().dao();

    public Page<AxbConf> paginate(Integer pageNumber, Integer pageSize, String openid) {

        String sqlExceptSelect = " from axb_conf where 1=1";
        if(StrKit.notBlank(openid)){
            sqlExceptSelect  = sqlExceptSelect + " and openid ='"+openid+"'";
        }
        return dao.paginate(pageNumber,pageSize,"select * ",sqlExceptSelect);
    }


    public void delete(Integer id) {
        dao.deleteById(id);
    }

    public Integer getIdByName(String s) {
        AxbConf f = dao.findFirst("select * from axb_conf where type = ?",s);
        if(null !=f){
            return f.getId();
        }else {
            return null;
        }
    }

    public String getTypeById(Integer id){
        return dao.findById(id).getType();
    }

    public List list() {
         List<AxbConf> list = dao.find("select DISTINCT type from axb_conf where type is not null");

         List resultList = new ArrayList();
         for(AxbConf f:list){
             resultList.add(f.getType());
         }
         return resultList;

    }

    public boolean exist(String openid) {
        AxbConf f = dao.findFirst("select * from axb_conf where openid = ?",openid);
        if(f==null){
            return false;
        }else{
            return true;
        }
    }
}
